package lruCache;

public class DoubleList {

    /**
     * 头尾的虚结点
     */
    private Node head, tail;

    /**
     * 链表元素数
     */
    private int size;

    public DoubleList(){
        head = new Node(0, 0);
        tail = new Node(0,0);
        head.next = tail;
        tail.prev = head;
        size = 0;
    }

    public void addNode(Node node){
        node.prev = tail.prev;
        node.next = tail;
        tail.prev = node;
        node.prev.next = node;
        size++;
    }

    public void removeNode(Node node){
        node.prev.next = node.next;
        node.next.prev = node.prev;
        size--;
    }

    public Node removeFirst(){
        if(head.next == tail){
            return null;
        }
        Node first = head.next;
        removeNode(first);
        return first;
    }

    public int size(){
        return size;
    }



}
